<!--
 * @Author: Dorange.Wang
 * @Date: 2021-04-02 16:09:55
 * @LastEditors: your name
 * @LastEditTime: 2021-04-06 11:23:50
 * @Description: file content
-->

<template>
  <el-dialog :visible="showVisible" center :show-close="false" width="600px">
    <div class="b g3 f16 tl" slot="title">
      <div class="ks-row-between pl15 pr15">
        <span>移动脚本</span>
        <span
          class="el-icon-close g9 f26 poi"
          @click="showVisible = false"
        ></span>
      </div>
    </div>

    <el-form class="pl30 pr30" :model="formData" ref="form" label-width="120px">
      <el-form-item
        label="文件夹"
        prop="folderId"
        :rules="[
          { required: true, message: '请选择文件夹', trigger: 'change' },
        ]"
      >
        <el-select v-model="formData.folderId" style="width: 400px">
          <el-option
            v-for="folder in folderList"
            :key="folder.id"
            :value="folder.id"
            :label="folder.name"
          />
        </el-select>
      </el-form-item>
    </el-form>

    <div slot="footer" class="tr">
      <el-button @click="showVisible = false">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { putHmscriptMove } from '@/apis/paas/HmScriptController.js'

export default {
  data() {
    return {
      showVisible: false,
      formData: {},
      folderList: [],
      callback: () => {},
      validator: (rule, value, callback) => {
        callback();
      },
    };
  },

  methods: {
    editForm(record, options = {}) {
      this.formData = { ...record };
      this.folderList = options.folderList;
      return this.showModel();
    },
    showModel() {
      this.showVisible = true;
      this.$nextTick(() => {
        this.$refs.form.clearValidate();
      });
      return {
        then: (callback) => {
          if (typeof callback === "function") {
            this.callback = callback;
          }
        },
      };
    },
    async submit() {
      try {
        await this.$refs.form.validate();
        const { id, folderId } = this.formData;
        const params = {
          id,
          folderId,
        };
        putHmscriptMove(params).then((res) => {
          this.showVisible = false;
          this.callback();
        });
      } catch (error) {
        console.log(error);
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
